package com.example.campusproject.adapter;

import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.components.*;

public class PageItemAdapter extends PageSliderProvider {
    private AbilitySlice context;
    private int[] images;

    public PageItemAdapter(AbilitySlice context, int[] images) {
        this.context = context;
        this.images = images;
    }

    @Override
    public int getCount() {
        return images.length;
    }

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        //创建图片组件
        Image image=new Image(context);
        //设置图片平铺Image组件的所有宽高
        image.setScaleMode(Image.ScaleMode.STRETCH);
        //设置图片的高宽
        image.setLayoutConfig(
                new StackLayout.LayoutConfig(
                        StackLayout.LayoutConfig.MATCH_PARENT,
                        StackLayout.LayoutConfig.MATCH_PARENT));
        image.setPixelMap(images[i]);
        componentContainer.addComponent(image);
        return image;
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent((Component) o);
    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return true;
    }
}
